#! /bin/bash
# usage: cfg.sh arm|x86 ipc|20
# $1 -- assign the architecture
# $2 -- assign the ffmpeg version

ARCH="x86"

# work dirs
IPC_FFDIR=$PWD/ipc_ffmpeg
FF20_DIR=$PWD/ffmpeg-2.0

# install vars
INSTALL_ROOT=$PWD/install
ARM_INSTDIR=$INSTALL_ROOT/arm
X86_INSTDIR=$INSTALL_ROOT/x86

# cross compile settings
CROSS_PREFIX='/opt/hisi-linux/x86-arm/gcc-3.4.3-uClibc-0.9.28/usr/bin/arm-hismall-linux-'
CROSS_CC='arm-hismall-linux-gcc'
CROSS_ARCH='armv5te' # ARM926EJ-S

# FFmpeg configure options
# general options for both arch
CFG_OPT='--disable-runtime-cpudetect --disable-swscale-alpha'
PRO_OPT='--disable-programs'
DOC_OPT='--disable-doc'

COM_OPT='--disable-avdevice --disable-swresample --disable-swscale --disable-postproc --disable-avfilter --disable-avresample --disable-w32threads --disable-os2threads --disable-network --disable-dct --disable-dwt --disable-lsp --disable-lzo --disable-mdct --disable-rdft --disable-fft'

OTH_OPT="--disable-hwaccels --disable-parsers --disable-bsfs --disable-indevs --disable-outdevs --disable-devices --disable-filters"

CODEC_OPT="--disable-encoders --disable-decoders --enable-encoder=adpcm_g726 --enable-encoder=h263p --enable-encoder=mjpeg --enable-encoder=pcm_alaw --enable-decoder=adpcm-g726 --enable-decoder=h263p --enable-decoder=h264 --enable-decoder=mjpeg --enable-decoder=pcm_alaw "
MUXER_OPT="--disable-muxers --disable-demuxers --enable-muxer=h264 --enable-muxer=mjpeg --enable-muxer=pcm_alaw --enable-demuxer=h264 --enable-demuxer=mjpeg --enable-demuxer=pcm_alaw"
PROTO_OPT="--disable-protocols --enable-protocol=file"

# HWACC_OPT='--disable-dxva2 --disable-vaapi --disable-vdpau'

OPTIM_OPT='--disable-yasm --disable-asm'

DEVELP_OPT='--disable-debug --disable-random'

# arch relevant options
ARM_OPT="--prefix=${ARM_INSTDIR} --enable-cross-compile --cross-prefix=${CROSS_PREFIX} --target-os=linux --cc=${CROSS_CC} --arch=${CROSS_ARCH} --cpu=${CROSS_ARCH} " 
X86_OPT="--prefix=${X86_INSTDIR}"

GENER_OPTS="$CFG_OPT $PRO_OPT $DOC_OPT $COM_OPT $OTH_OPT $CODEC_OPT $MUXER_OPT $PRO_OPT $OPTIM_OPT $DEVELP_OPT"

# exit 0

# echo $#
# if [ $# -gt 1 -a "$2" == "ipc" ]
if [ $# -gt 1 ] && [ "$2" = "ipc" ]
then
	pushd $IPC_FFDIR
else
	pushd $FF20_DIR
fi

if [ $# -gt 0 ]
then
	ARCH=$1
fi

# popd && exit 0

# if [ "$ARCH" == "ARM" -o "$ARCH" == "arm" ]
if [ "$ARCH" = "ARM" ] || [ "$ARCH" = "arm" ]
then
	./configure $ARM_OPT $GENER_OPTS
else
	./configure $X86_OPT $GENER_OPTS
fi

if [ $? -eq 0 ]
then
	make && make install 
fi

popd 

exit 0

